package com.zyk.leetcode;

/**
 * @author zhangsan
 * @date 2021/6/14 13:18
 */
public class C55 {

    public static boolean canJump(int[] nums) {
        if (nums == null || nums.length < 2) return true;
        int max = nums[0];    // 能跳的最远位置
        int n = nums.length;
        for (int i = 1; i <= max && max < n - 1; i++) {
            max = Math.max(max, i + nums[i]);
        }
        return max >= (n - 1);
    }


    public static void main(String[] args) {
//        int[] nums = {2, 3, 1, 1, 4};
        int[] nums = {1, 2, 3};
        System.out.println(canJump(nums));
    }

}
